package com.example.myapplication;

import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class configActivity2 extends AppCompatActivity {
    EditText d_rate,u_rate,w_rate;
    public static final String TAG="config";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_config2);
        d_rate=findViewById(R.id.d_rate);
        u_rate=findViewById(R.id.u_rate);
        w_rate=findViewById(R.id.w_rate);
        SharedPreferences sharedPreferences=getSharedPreferences("myrate", Activity.MODE_PRIVATE);
        Intent intent=getIntent();
        float d1=sharedPreferences.getFloat("new_dollar_rate_key",1.2f);
        d_rate.setText(""+d1);
        float u1=sharedPreferences.getFloat("new_euro_rate_key",0.3f);
        u_rate.setText(""+u1);
        float w1=sharedPreferences.getFloat("new_won_rate_key",0.2f);
        w_rate.setText(""+w1);
    }
    public void click(View v){
        d_rate=findViewById(R.id.d_rate);
        u_rate=findViewById(R.id.u_rate);
        w_rate=findViewById(R.id.w_rate);
        String d=d_rate.getText().toString();
        String u=u_rate.getText().toString();
        String w=w_rate.getText().toString();
        float d_rate=Float.valueOf(d);
        float u_rate=Float.valueOf(u);
        float w_rate=Float.valueOf(w);
        Intent main=getIntent();
        Bundle bdl=new Bundle();
        bdl.putFloat("new_dollar_rate_key",d_rate);
        bdl.putFloat("new_euro_rate_key",u_rate);
        bdl.putFloat("new_won_rate_key",w_rate);
        main.putExtras(bdl);
        //startActivity(main);
        setResult(2,main);
        finish();
    }
}